/**
 * 监测站点管理系统 Entity
 * 
 * 包含三个核心实体：
 * 1. StationType - 测站类型管理
 * 2. StationInfo - 测站编码管理  
 * 3. MonitoringData - 监测数据管理
 * 
 * 使用 TypeORM + UUID 主键 + 无关联关系设计
 * 兼容 PostgreSQL 数据库
 */

// 测站类型实体
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn ,Unique} from 'typeorm';

@Entity('station_type')
export class StationType {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ 
    name: 'station_type_code', 
    comment: '测站类型编码',
  })
  stationTypeCode: string;

  @Column({ 
    name: 'station_type_name', 
    comment: '测站类型名称' 
  })
  stationTypeName: string;

  @Column({ 
    name: 'data_type_code', 
    comment: '数据类型编码',
    nullable: true 
  })
  dataTypeCode?: string;

  @Column({ 
    name: 'data_type_name', 
    comment: '数据类型名称',
    nullable: true 
  })
  dataTypeName?: string;

  @Column({ 
    name: 'original_column_name', 
    comment: '原始数据列名',
    nullable: true 
  })
  originalColumnName?: string;

  @Column({ 
    name: 'original_column_number', 
    type: 'int', 
    comment: '原始数据列号',
    nullable: true 
  })
  originalColumnNumber?: number;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt: Date;
}

// 测站编码实体
@Entity('station_info')
export class StationInfo {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ 
    name: 'stcd', 
    comment: '测站编码',
    unique: true 
  })
  stcd: string;

  @Column({ 
    name: 'stnm', 
    comment: '测站名称',
    nullable: true 
  })
  stnm?: string;

  @Column({ 
    name: 'lon', 
    type: 'decimal', 
    precision: 10, 
    scale: 6, 
    comment: '经度',
    nullable: true 
  })
  lon?: number;

  @Column({ 
    name: 'lat', 
    type: 'decimal', 
    precision: 10, 
    scale: 6, 
    comment: '纬度',
    nullable: true 
  })
  lat?: number;

  @Column({ 
    name: 'source', 
    comment: '数据来源',
    nullable: true 
  })
  source?: string;

  @Column({ 
    name: 'geo', 
    type: 'text', 
    comment: '地理位置信息',
    nullable: true 
  })
  geo?: string;

  // 新增：测站类型编码字段
  @Column({
    name: 'station_type_code',
    comment: '测站类型编码',
    nullable: true
  })
  stationTypeCode?: string;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt: Date;
}

// 监测数据实体
@Unique(['dataType', 'monitoringDate'])
@Entity('monitoring_data')
export class MonitoringData {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ 
    name: 'station_code', 
    comment: '测站编码' 
  })
  stationCode: string;

  @Column({ 
    name: 'data_type', 
    comment: '数据类型',
    nullable: true 
  })
  dataType?: string;

  // 新增：测站类型编码字段
  @Column({
    name: 'station_type_code',
    comment: '测站类型编码',
    nullable: true
  })
  stationTypeCode?: string;

  // 新增：测站类型名称字段
  @Column({
    name: 'station_type_name',
    comment: '测站类型名称',
    nullable: true
  })
  stationTypeName?: string;

  @Column({ 
    name: 'monitoring_date', 
    type: 'timestamp',
    comment: '监测日期',
    nullable: true 
  })
  monitoringDate?: Date;

  @Column({ 
    name: 'monitoring_value', 
    type: 'decimal', 
    precision: 15, 
    scale: 4, 
    comment: '监测数据',
    nullable: true 
  })
  monitoringValue?: number;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt: Date;
}